﻿using Medicine.Entity;
using Medicine.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Medicine
{
    public partial class register : Form
    {
        private UserService us = new UserService();
        public register()
        {
            InitializeComponent();
        }

        //确定
        private void button1_Click(object sender, EventArgs e)
        {
            User u = new User();
            u.Name = this.textBox3.Text.Trim();
            u.Number = this.textBox1.Text.Trim();
            u.Passwd = this.textBox2.Text.Trim();
            u.Price = 0;
            if(this.checkBox1.Checked==false)
            u.Authority = 1;
            else
                u.Authority = 0;
            us.check(u);
            if (u.Name != "" && u.Number != "" && u.Passwd != "")
            {
                if (u.Id != -1)
                {
                    MessageBox.Show("已经存在！！！");
                }
                else
                {
                    try
                    {
                        us.insert(u);
                        Form1 f = new Form1();
                        this.Close();
                        f.Show();
                    }
                    catch (Exception c)
                    {
                        MessageBox.Show("数据库出错....");
                    }
                }
            }
            else
            {
                MessageBox.Show("必须填完");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            this.Close();
            f.Show();
        }

        private void register_Load(object sender, EventArgs e)
        {

        }
    }
}
